package com.example.demo.Controller;

import com.example.demo.Task.AsyncTest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.Future;

@RestController
public class AsyncTaskController {
    @Resource
    private AsyncTest asyncTest;

    @RequestMapping("/asyncTest")
    public String test1() throws Exception{
        long start = System.currentTimeMillis();
        Future<Boolean> a = asyncTest.doTask01();
        Future<Boolean> b = asyncTest.doTask02();

         while (!a.isDone() || !b.isDone()){
             if(a.isDone() && b.isDone()){
                 break;
             }
         }
         long end = System.currentTimeMillis();

         String times = "任务总耗时："+(end-start)+"毫秒";
         return times;
    }
}
